//  
//  Sprawdzacz
//  
//  Author:
//       Grzegorz Żur <grzegorz.zur@gmail.com>
// 
//  Copyright (c) 2010-2011 Grzegorz Żur
// 
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

using System;
using System.IO;
using System.Collections;
using System.Collections.Specialized;

namespace Sprawdzacz
{

	public class Dictionary
	{

		private StringDictionary dictionary = new StringDictionary ();

		public Dictionary (Stream stream)
		{
			if (stream == null)
				throw new ArgumentNullException ("stream cannot be null");
			TextReader reader = new StreamReader (stream);
			try {
				string line = null;
				while ((line = reader.ReadLine ()) != null) {
					if (line.Length == 0)
						continue;
					string[] split = line.Split ('\t');
					if (split.Length != 2)
						throw new FormatException ("wrong dictionary format");
					string code = split[0];
					string name = split[1];
					dictionary.Add (code, name);
				}
			} finally {
				reader.Close ();
			}
		}

		public bool Exists (string code)
		{
			return dictionary.ContainsKey (code);
		}

		public string Decode (string code)
		{
			return dictionary[code];
		}
		
	}
	
}
